import random
import asyncio
from autogen_core import CancellationToken
from autogen_core.tools import FunctionTool
from typing_extensions import Annotated


async def get_stock_price(ticker: str, date: Annotated[str, "Date in YYYY/MM/DD"]) -> float:
    # Returns a random stock price for demonstration purposes.
    return random.uniform(10, 200)

stock_price_tool = FunctionTool(get_stock_price, description="Get the stock price.")
async def main1(): 
    # Create a function tool.

    # Run the tool.
    cancellation_token = CancellationToken()
    result = await stock_price_tool.run_json({"ticker": "AAPL", "date": "2021/01/01"}, cancellation_token)

    # Print the result.
    print(stock_price_tool.return_value_as_string(result))

asyncio.run(main1())

import json

from autogen_core.models import AssistantMessage, FunctionExecutionResult, FunctionExecutionResultMessage, UserMessage
from autogen_ext.models.openai import OpenAIChatCompletionClient

from autogen_ext.models.ollama import OllamaChatCompletionClient
model_client = OllamaChatCompletionClient(
        model="hhao/qwen2.5-coder-tools:latest",
        #model="llama3.1:latest",
        host="http://192.168.99.142:11434", 
         model_info={
        "vision": False,
        "function_calling": True,
        "json_output": True,
        "family": "unknow",
        "structed_output":True,
        },
    )
async def main2():
    # Create a user message.
    user_message = UserMessage(content="What is the stock price of AAPL on 2021/01/01?", source="user")

    # Run the chat completion with the stock_price_tool defined above.
    cancellation_token = CancellationToken()
    create_result = await model_client.create(
        messages=[user_message], tools=[stock_price_tool], cancellation_token=cancellation_token
    )
    print(create_result.content)
asyncio.run(main2())
